package com.ems.controller.Invigilate.room;

import com.ems.pojo.Invigilate.room.ExaminationPaper;
import com.ems.pojo.Invigilate.room.TestScoreResult;
import com.ems.pojo.data.RequestData;
import com.ems.pojo.data.ResultData;
import com.ems.pojo.data.RetunResult;
import com.ems.pojo.data.ReturnPageResult;
import com.ems.pojo.statistics.Referer;
import com.ems.pojo.statistics.ScoreStatistics;
import com.ems.pojo.user.User;
import com.ems.service.Invigilate.room.TestScoreResultService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

/**
 * @Auther: 伟伟
 * @Date: 2020/3/12
 * @Description: 描述
 * @Version: 1.0
 */
@Controller
@CrossOrigin //允许所有ip跨域
@RequestMapping("/testScoreResult")
public class TestScoreResultController {
    @Autowired
    @Qualifier("testScoreResultService")
    private TestScoreResultService testScoreResultService;

    /**
     * 成绩统计
     * @param requestData
     * @return
     */
    @RequestMapping("/scoreStatistics")
    @ResponseBody
    public ResultData scoreStatistics(@RequestBody RequestData requestData){
        ReturnPageResult.setPageHelperInfo(requestData);
        List<TestScoreResult> list = testScoreResultService.scoreStatistics(requestData.getMap());
        return ReturnPageResult.AssemblyData(list);
    }

    /**
     * 分数统计
     * @param testScoreResult
     * @return
     */
    @RequestMapping("/getRefererInfo")
    @ResponseBody
    public ResultData getRefererInfo(@RequestBody TestScoreResult testScoreResult){
        List<Referer> list = testScoreResultService.getRefererInfo(testScoreResult);
        return RetunResult.AssemblyData(list);
    }

    /**
     * 成绩统计
     * @param testScoreResult
     * @return
     */
    @RequestMapping("/getScoreStatistics")
    @ResponseBody
    public ResultData getScoreStatistics(@RequestBody TestScoreResult testScoreResult){
        ScoreStatistics scoreStatistics = testScoreResultService.getScoreStatistics(testScoreResult);
        return RetunResult.AssemblyData(scoreStatistics);
    }

    /**
     *
     * @param testScoreResult
     * @return
     */
    @RequestMapping("/getScoreStatisticsByRpIdAndId")
    @ResponseBody
    public ResultData getScoreStatisticsByRpIdAndId(@RequestBody TestScoreResult testScoreResult, HttpServletRequest request){
        User user = (User) request.getSession().getAttribute("user");
        testScoreResult.setId(user.getId());
        TestScoreResult testScoreResult1 = testScoreResultService.getScoreStatisticsByRpIdAndId(testScoreResult);
        return RetunResult.AssemblyData(testScoreResult1);
    }
}
